package com.ctshk.sapp.finance.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.finance.dto.onaccount.OffAccountApplyDTO;
import com.ctshk.rpc.finance.dto.onaccount.OffAccountListDTO;
import com.ctshk.rpc.finance.dto.onaccount.OffAccountUsedListDTO;
import com.ctshk.rpc.finance.dto.onaccount.OnAccountListDTO;
import com.ctshk.rpc.finance.req.bill.BillCheckApprovalReq;
import com.ctshk.rpc.finance.req.onaccount.*;
import com.ctshk.rpc.finance.service.IFinanceOffAccountApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 财务销账申请记录 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-31
 */
@RestController
@Api(value = "销账申请", tags = "销账申请")
@RequestMapping("/finance-off-account-apply")
public class FinanceOffAccountApplyController extends BaseController {

    @DubboReference
    private IFinanceOffAccountApplyService offAccountApplyService;


    @ApiOperation(value = "列表", notes = "列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "销账申请-列表", operDesc = "销账申请-列表")
    @PostMapping("/list")
    public Result<List<OffAccountListDTO>> list(@RequestBody @Valid OffnAccountListReq req) {
        return offAccountApplyService.list(req);
    }

    @ApiOperation(value = "申请销账", notes = "申请销账（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.ADD, operTitle = "申请销账", operDesc = "申请销账")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid OffAccountAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return offAccountApplyService.add(req);
    }

    @ApiOperation(value = "详情", notes = "详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "销账申请-详情", operDesc = "销账申请-详情")
    @PostMapping("/detail")
    public Result<OffAccountApplyDTO> detail(@RequestBody @Valid OffAccountIdReq req) {
        return offAccountApplyService.detail(req);
    }

    @ApiOperation(value = "审批", notes = "审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "销账申请-审批", operDesc = "销账申请-审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid OffAccountApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return offAccountApplyService.approval(req);
    }

    @ApiOperation(value = "预收明细-使用记录", notes = "预收明细-使用记录（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "销账申请-预收明细-使用记录", operDesc = "销账申请-预收明细-使用记录")
    @PostMapping("/used-list")
    public Result<PageResponse<OffAccountUsedListDTO>> usedList(@RequestBody @Valid OffAccountUsedListReq req) {
        return offAccountApplyService.usedList(req);
    }

}
